package org.anno.chunkdb;

/**
 * Base class for query plans. A query plan can accept {@link ResponseVisitor}s.
 */
public abstract class QueryPlan implements Host<ResponseVisitor> {

  protected final Metadata.Table table;

  /**
   * Zero means no order is guaranteed. Positive value means ascending, negative descending,
   * according to values in index abs(k)+1.
   */
  protected final int sortedColumn;

  protected QueryPlan(Metadata.Table table, int sortedColumn) {
    this.table = table;
    this.sortedColumn = sortedColumn;
  }

  protected static void acceptForAllColumns(Metadata.Table table, ResponseVisitor visitor) {
    for (int i = 0; i < table.getColumnCount(); i++) {
      visitor.visitColumn(i, table.getColumn(i).getName());
    }
  }
}
